
#include "include.h"
#include "qt_guieventdispatcher_adapter.h"
#include "../qt_utils.h"

using namespace gui;
using namespace qtgui;


QWidgetGuiEventDispatcherAdapter::QWidgetGuiEventDispatcherAdapter(QWidget* parent)
: QWidget(parent), guieventdispatcher(NULL)
{
}

QWidgetGuiEventDispatcherAdapter::~QWidgetGuiEventDispatcherAdapter()
{
}

void QWidgetGuiEventDispatcherAdapter::setDelegate(GuiEventDispatcher* _delegate)
{
    guieventdispatcher = _delegate;           
}



void QWidgetGuiEventDispatcherAdapter::paintEvent(QPaintEvent *event)
{
    QWidget::paintEvent(event);
    if(guieventdispatcher!=NULL && event!=NULL)
    {
//                guieventdispatcher->repaint_from_qt(event);
		guieventdispatcher->emitPaintEvent();
    }
}


void QWidgetGuiEventDispatcherAdapter::resizeEvent(QResizeEvent *event)
{
    QWidget::resizeEvent(event);
    if(guieventdispatcher!=NULL && event!=NULL)
    {
//                guieventdispatcher->resize_from_qt(event);
		const SizeEvent& sizeevent = qtgui::buildEvent(*event);
		guieventdispatcher->emitResizeEvent(sizeevent);

    }
}

void QWidgetGuiEventDispatcherAdapter::mousePressEvent(QMouseEvent *event)
{
    QWidget::mousePressEvent(event);
    if(guieventdispatcher!=NULL && event!=NULL)
    {
//                guieventdispatcher->mouse_press_from_qt(event);
		const MouseEvent& mouseevent = qtgui::buildEvent(*event);
		guieventdispatcher->emitMouseEvent(mouseevent);
    }
}

void QWidgetGuiEventDispatcherAdapter::mouseReleaseEvent(QMouseEvent *event)
{
    QWidget::mouseReleaseEvent(event);
    if(guieventdispatcher!=NULL && event!=NULL)
    {
//                guieventdispatcher->mouse_release_from_qt(event);
		const MouseEvent& mouseevent = qtgui::buildEvent(*event);
		guieventdispatcher->emitMouseEvent(mouseevent);
	}
}

void QWidgetGuiEventDispatcherAdapter::mouseDoubleClickEvent(QMouseEvent *event)
{
    QWidget::mouseMoveEvent(event);
    if(guieventdispatcher!=NULL && event!=NULL)
    {
//                guieventdispatcher->mouse_move_from_qt(event);
		const MouseEvent& mouseevent = qtgui::buildEvent(*event);
		guieventdispatcher->emitMouseEvent(mouseevent);
    }
}

void QWidgetGuiEventDispatcherAdapter::mouseMoveEvent(QMouseEvent *event)
{
    QWidget::mouseMoveEvent(event);
    if(guieventdispatcher!=NULL && event!=NULL)
    {
//                guieventdispatcher->mouse_move_from_qt(event);
		const MouseEvent& mouseevent = qtgui::buildEvent(*event);
		guieventdispatcher->emitMouseEvent(mouseevent);
    }
}

void QWidgetGuiEventDispatcherAdapter::wheelEvent(QWheelEvent *event)
{
    QWidget::wheelEvent(event);
    if(guieventdispatcher!=NULL && event!=NULL)
    {
//                guieventdispatcher->wheel_from_qt(event);
		std::cout << event->type() << std::endl;
    }
}

void QWidgetGuiEventDispatcherAdapter::keyPressEvent(QKeyEvent *event)
{
    QWidget::keyPressEvent(event);
    if(guieventdispatcher!=NULL && event!=NULL)
    {
//                guieventdispatcher->key_press_from_qt(event);
		std::cout << event->type() << std::endl;
    }
}

void QWidgetGuiEventDispatcherAdapter::keyReleaseEvent(QKeyEvent *event)
{
    QWidget::keyReleaseEvent(event);
    if(guieventdispatcher!=NULL && event!=NULL)
    {
//                guieventdispatcher->key_release_from_qt(event);
		std::cout << event->type() << std::endl;
    }

}


